/********************************
This program generates estimates for
Figure 2B in the paper
************************************/

#delimit ;

include "./config.do" ;
cap log close ; 
log using $logdir/01.06.percentile_assoc_byyear.log, replace; 

use "$datadir/percentile_assoc_byyear.dta", clear ; 
rename fte_percentile percentile ;

twoway (lowess share_onlyinstate percentile if year == 1,bwidth(0.1))
       (lowess share_onlyinstate percentile if year == 5,bwidth(0.1) lpattern(dash))
       (lowess share_onlyinstate percentile if year == 10,bwidth(0.1) lpattern(longdash_dot)),
       legend(label(1 "Year = 1") label(2 "Year = 5") label(3 "Year = 10")) ytitle("Share Employed In-State")
       xtitle("National Earnings Percentile")
       ytitle("Share In-State")
       yscale(range(0(0.1)1)) 
       ylabel(0(.1)1);

graph export "$resultsdir/share_instate_byyear_assoc.png", replace ;

/**********************************************
Creating support file
**********************************************/
keep if year_postgrad == 1 | year_postgrad == 5 | year_postgrad == 10 ;

gen instate = _freq_*share_onlyinstate ; 
gen outofstate = _freq_*(1-share_onlyinstate) ;

keep percentile year_postgrad instate outofstate _freq_ ;
rename _freq_ nobs ; 

save "$supportdir/support_share_assoc_byyear.dta", replace; 
outsheet using $supportdir/support_share_assoc_byyear.csv, comma replace; 
